package com.csiec.clock.fragment.login;

import androidx.databinding.DataBindingUtil;
import androidx.lifecycle.ViewModelProvider;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.navigation.NavController;
import androidx.navigation.Navigation;

import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.csiec.clock.R;
import com.csiec.clock.activity.LoginActivity;
import com.csiec.clock.activity.MainActivity;
import com.csiec.clock.databinding.LoginFragmentBinding;
import com.csiec.clock.view.model.LoginViewModel;

public class LoginFragment extends Fragment {

    private LoginViewModel loginViewModel;
    private LoginFragmentBinding binding;

    private final String TAG = "LoginFragment";


    public static LoginFragment newInstance() {
        return new LoginFragment();
    }

    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        binding = DataBindingUtil.inflate(inflater, R.layout.login_fragment, container, false);
        return binding.getRoot();
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        loginViewModel = new ViewModelProvider(this).get(LoginViewModel.class);
        loginViewModel.init(getActivity(), binding);
        binding.setLoginViewModel(loginViewModel);
        binding.setLifecycleOwner(this);

        binding.btnRegister.setOnClickListener(this::register);
    }


    private void register(View v) {
        NavController controller = Navigation.findNavController(v);
        controller.navigate(R.id.action_loginFragment_to_registerFragment);
    }

}